#!/usr/bin/env bash
# 关闭防火墙
echo '>>>>>>>>>>>>>>>>>>>> disable firewalld'
systemctl stop firewalld
systemctl disable firewalld

# 关闭 selinux
echo '>>>>>>>>>>>>>>>>>>>> disable selinux'
setenforce 0
sed -i 's/=enforcing/=disabled/g' /etc/selinux/config

# 关闭 swap
echo '>>>>>>>>>>>>>>>>>>>> disable swap, swap输出为0表示成功'
swapoff -a
sed -i '/swap/s/^/#/' /etc/fstab
## 验证
free -g | grep Swap

# 设置主机名与IP关系
echo '>>>>>>>>>>>>>>>>>>>> set host name resolution'
cat >> /etc/hosts <<EOF
192.168.56.101 k8s-node1
192.168.56.102 k8s-node2
192.168.56.103 k8s-node3
EOF
cat /etc/hosts

# 设置resolv
echo '>>>>>>>>>>>>>>>>>>>> set resolv'
echo "nameserver 8.8.8.8">/etc/resolv.conf
cat /etc/resolv.conf
systemctl restart network

# 指定本机hostname
#hostnamectl set-hostname k8s-node1

# 将桥接的IPv4流量传递到iptables的链
echo '>>>>>>>>>>>>>>>>>>>> set k8s.conf'
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
EOF
sysctl --system

# 同步时间
echo '>>>>>>>>>>>>>>>>>>>> update date'
date
yum install -y ntpdate
ntpdate time.windows.com
timedatectl set-timezone Asia/Shanghai
date